package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.OrderStatisticsVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    //向订单表中插入数据
    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);


    @Update("update orders set status = #{orderStatus},pay_status = #{orderPaidStatus} ,checkout_time = #{check_out_time} where id = #{id}")
    void updateStatus(Integer orderStatus, Integer orderPaidStatus, LocalDateTime check_out_time, Long id);

    //分页查询历史订单
    Page<Orders> pageQueryHistoryOrders(OrdersPageQueryDTO ordersPageQueryDTO);

    //根据id查询订单
    Orders getAllByid(Long id);

    //取消订单取消订单
    void cancleById(Orders orders);

    //管理端分页查询订单
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    //各个状态的订单数量统计
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer toBeConfirmed);

    //管理端取消订单
    void adminCancleById(Orders orders);

    //拒单
    void updaterd(Orders orders);

    //查询超时订单
    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> getTimeOutOrder(int status, LocalDateTime time);

    //催单
    @Select("select * from orders where id = #{id}")
    Orders getAllByOrderId(Long id);

    //查询每天的营业额
    Double getSumAmount(Map map);

    //查询每天订单总数
    Integer getOrderCount(LocalDateTime beginTime, LocalDateTime endTime);

    //查询每天有效订单数
    Integer getValidOrderCount(Map map);


    //top10
    List<GoodsSalesDTO> getBytime(LocalDateTime beginTime, LocalDateTime endTime);

    //查询当天各个状态的订单数量
    Integer getOrderCountByStatus(LocalDateTime begin, LocalDateTime end, Integer status);
}
